package f;

import com.huawei.hms.android.HwBuildEx.VersionCodes;
import f.f0.c;
import f.f0.e.e;
import f.f0.f.g;
import f.f0.j.f;
import f.f0.l.d;
import java.io.IOException;
import java.lang.ref.Reference;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.Socket;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import javax.net.SocketFactory;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;

/* compiled from: OkHttpClient */
public class v implements Cloneable {
    public static final List<w> B = c.q(w.HTTP_2, w.HTTP_1_1);
    public static final List<h> C = c.q(h.g, h.h);
    public final int A;
    public final k a;
    @Nullable
    public final Proxy b;
    public final List<w> c;
    public final List<h> d;
    public final List<s> e;
    public final List<s> f;
    public final f.m.b g;
    public final ProxySelector h;
    public final j i;
    @Nullable
    public final e j;
    public final SocketFactory k;
    public final SSLSocketFactory l;
    public final f.f0.l.c m;
    public final HostnameVerifier n;
    public final e o;
    public final b p;
    public final b q;
    public final g r;
    public final l s;
    public final boolean t;
    public final boolean u;
    public final boolean v;
    public final int w;
    public final int x;
    public final int y;
    public final int z;

    /* compiled from: OkHttpClient */
    public static final class b {
        public int A;
        public k a;
        @Nullable
        public Proxy b;
        public List<w> c;
        public List<h> d;
        public final List<s> e;
        public final List<s> f;
        public f.m.b g;
        public ProxySelector h;
        public j i;
        @Nullable
        public e j;
        public SocketFactory k;
        @Nullable
        public SSLSocketFactory l;
        @Nullable
        public f.f0.l.c m;
        public HostnameVerifier n;
        public e o;
        public b p;
        public b q;
        public g r;
        public l s;
        public boolean t;
        public boolean u;
        public boolean v;
        public int w;
        public int x;
        public int y;
        public int z;

        public b() {
            this.e = new ArrayList();
            this.f = new ArrayList();
            this.a = new k();
            this.c = v.B;
            this.d = v.C;
            this.g = new n(m.a);
            ProxySelector proxySelector = ProxySelector.getDefault();
            this.h = proxySelector;
            if (proxySelector == null) {
                this.h = new f.f0.k.a();
            }
            this.i = j.a;
            this.k = SocketFactory.getDefault();
            this.n = d.a;
            this.o = e.c;
            b bVar = b.a;
            this.p = bVar;
            this.q = bVar;
            this.r = new g();
            this.s = l.a;
            this.t = true;
            this.u = true;
            this.v = true;
            this.w = 0;
            this.x = VersionCodes.CUR_DEVELOPMENT;
            this.y = VersionCodes.CUR_DEVELOPMENT;
            this.z = VersionCodes.CUR_DEVELOPMENT;
            this.A = 0;
        }

        public b a(s sVar) {
            this.e.add(sVar);
            return this;
        }

        public b b(long j, TimeUnit timeUnit) {
            this.x = c.d("timeout", j, timeUnit);
            return this;
        }

        public b c(List<w> list) {
            ArrayList arrayList = new ArrayList(list);
            w wVar = w.H2_PRIOR_KNOWLEDGE;
            StringBuilder stringBuilder;
            if (!arrayList.contains(wVar) && !arrayList.contains(w.HTTP_1_1)) {
                stringBuilder = new StringBuilder();
                stringBuilder.append("protocols must contain h2_prior_knowledge or http/1.1: ");
                stringBuilder.append(arrayList);
                throw new IllegalArgumentException(stringBuilder.toString());
            } else if (arrayList.contains(wVar) && arrayList.size() > 1) {
                stringBuilder = new StringBuilder();
                stringBuilder.append("protocols containing h2_prior_knowledge cannot use other protocols: ");
                stringBuilder.append(arrayList);
                throw new IllegalArgumentException(stringBuilder.toString());
            } else if (arrayList.contains(w.HTTP_1_0)) {
                stringBuilder = new StringBuilder();
                stringBuilder.append("protocols must not contain http/1.0: ");
                stringBuilder.append(arrayList);
                throw new IllegalArgumentException(stringBuilder.toString());
            } else if (arrayList.contains(null)) {
                throw new IllegalArgumentException("protocols must not contain null");
            } else {
                arrayList.remove(w.SPDY_3);
                this.c = Collections.unmodifiableList(arrayList);
                return this;
            }
        }

        public b d(long j, TimeUnit timeUnit) {
            this.y = c.d("timeout", j, timeUnit);
            return this;
        }

        public b e(long j, TimeUnit timeUnit) {
            this.z = c.d("timeout", j, timeUnit);
            return this;
        }

        public b(v vVar) {
            ArrayList arrayList = new ArrayList();
            this.e = arrayList;
            ArrayList arrayList2 = new ArrayList();
            this.f = arrayList2;
            this.a = vVar.a;
            this.b = vVar.b;
            this.c = vVar.c;
            this.d = vVar.d;
            arrayList.addAll(vVar.e);
            arrayList2.addAll(vVar.f);
            this.g = vVar.g;
            this.h = vVar.h;
            this.i = vVar.i;
            this.j = vVar.j;
            this.k = vVar.k;
            this.l = vVar.l;
            this.m = vVar.m;
            this.n = vVar.n;
            this.o = vVar.o;
            this.p = vVar.p;
            this.q = vVar.q;
            this.r = vVar.r;
            this.s = vVar.s;
            this.t = vVar.t;
            this.u = vVar.u;
            this.v = vVar.v;
            this.w = vVar.w;
            this.x = vVar.x;
            this.y = vVar.y;
            this.z = vVar.z;
            this.A = vVar.A;
        }
    }

    /* compiled from: OkHttpClient */
    public class a extends f.f0.a {
        public void a(f.q.a aVar, String str, String str2) {
            aVar.a.add(str);
            aVar.a.add(str2.trim());
        }

        public Socket b(g gVar, a aVar, g gVar2) {
            for (f.f0.f.c cVar : gVar.d) {
                if (cVar.g(aVar, null) && cVar.h() && cVar != gVar2.b()) {
                    if (gVar2.n == null && gVar2.j.n.size() == 1) {
                        Reference reference = (Reference) gVar2.j.n.get(0);
                        Socket c = gVar2.c(true, false, false);
                        gVar2.j = cVar;
                        cVar.n.add(reference);
                        return c;
                    }
                    throw new IllegalStateException();
                }
            }
            return null;
        }

        public f.f0.f.c c(g gVar, a aVar, g gVar2, d0 d0Var) {
            for (f.f0.f.c cVar : gVar.d) {
                if (cVar.g(aVar, d0Var)) {
                    gVar2.a(cVar, true);
                    return cVar;
                }
            }
            return null;
        }

        @Nullable
        public IOException d(d dVar, @Nullable IOException iOException) {
            return ((x) dVar).d(iOException);
        }
    }

    static {
        f.f0.a.a = new a();
    }

    public v() {
        this(new b());
    }

    public d a(y yVar) {
        x xVar = new x(this, yVar, false);
        xVar.d = ((n) this.g).a;
        return xVar;
    }

    public v(b bVar) {
        String str = "No System TLS";
        this.a = bVar.a;
        this.b = bVar.b;
        this.c = bVar.c;
        List<h> list = bVar.d;
        this.d = list;
        this.e = c.p(bVar.e);
        this.f = c.p(bVar.f);
        this.g = bVar.g;
        this.h = bVar.h;
        this.i = bVar.i;
        this.j = bVar.j;
        this.k = bVar.k;
        loop0:
        while (true) {
            Object obj = null;
            for (h hVar : list) {
                if (obj != null || hVar.a) {
                    obj = 1;
                }
            }
            break loop0;
        }
        SSLSocketFactory sSLSocketFactory = bVar.l;
        if (sSLSocketFactory != null || obj == null) {
            this.l = sSLSocketFactory;
            this.m = bVar.m;
        } else {
            try {
                TrustManagerFactory instance = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
                instance.init(null);
                TrustManager[] trustManagers = instance.getTrustManagers();
                if (trustManagers.length == 1 && (trustManagers[0] instanceof X509TrustManager)) {
                    X509TrustManager x509TrustManager = (X509TrustManager) trustManagers[0];
                    try {
                        f fVar = f.a;
                        SSLContext h = fVar.h();
                        h.init(null, new TrustManager[]{x509TrustManager}, null);
                        str = h.getSocketFactory();
                        this.l = str;
                        this.m = fVar.c(x509TrustManager);
                    } catch (GeneralSecurityException e) {
                        throw c.a(str, e);
                    }
                }
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("Unexpected default trust managers:");
                stringBuilder.append(Arrays.toString(trustManagers));
                throw new IllegalStateException(stringBuilder.toString());
            } catch (GeneralSecurityException e2) {
                throw c.a(str, e2);
            }
        }
        SSLSocketFactory sSLSocketFactory2 = this.l;
        if (sSLSocketFactory2 != null) {
            f.a.e(sSLSocketFactory2);
        }
        this.n = bVar.n;
        e eVar = bVar.o;
        f.f0.l.c cVar = this.m;
        if (!c.m(eVar.b, cVar)) {
            eVar = new e(eVar.a, cVar);
        }
        this.o = eVar;
        this.p = bVar.p;
        this.q = bVar.q;
        this.r = bVar.r;
        this.s = bVar.s;
        this.t = bVar.t;
        this.u = bVar.u;
        this.v = bVar.v;
        this.w = bVar.w;
        this.x = bVar.x;
        this.y = bVar.y;
        this.z = bVar.z;
        this.A = bVar.A;
        StringBuilder g;
        if (this.e.contains(null)) {
            g = c.b.a.a.a.g("Null interceptor: ");
            g.append(this.e);
            throw new IllegalStateException(g.toString());
        } else if (this.f.contains(null)) {
            g = c.b.a.a.a.g("Null network interceptor: ");
            g.append(this.f);
            throw new IllegalStateException(g.toString());
        }
    }
}
